*/
class SpecialMute extends FormSpecialPage {
+ const PAGE_NAME = 'Mute';
+
/** @var User */
private $target;
$this->centralIdLookup = CentralIdLookup::factory();
- parent::__construct( 'Mute', '', false );
+ parent::__construct( self::PAGE_NAME, '', false );
}
/**
parent::execute( $par );
$out = $this->getOutput();
- $out->addModules( 'mediawiki.special.pageLanguage' );
+ $out->addModules( 'mediawiki.misc-authed-ooui' );
}
/**
* @return bool
*/
public function onSubmit( array $data, HTMLForm $form = null ) {
- if ( !empty( $data['MuteEmail'] ) ) {
- $this->muteEmailsFromTarget();
- } else {
- $this->unmuteEmailsFromTarget();
+ foreach ( $data as $userOption => $value ) {
+ if ( $value ) {
+ $this->muteTarget( $userOption );
+ } else {
+ $this->unmuteTarget( $userOption );
+ }
}
return true;
}
/**
- * Un-mute emails from target
+ * Un-mute target
+ *
+ * @param string $userOption up_property key that holds the blacklist
*/
- private function unmuteEmailsFromTarget() {
- $blacklist = $this->getBlacklist();
+ private function unmuteTarget( $userOption ) {
+ $blacklist = $this->getBlacklist( $userOption );
$key = array_search( $this->targetCentralId, $blacklist );
if ( $key !== false ) {
$blacklist = implode( "\n", $blacklist );
$user = $this->getUser();
- $user->setOption( 'email-blacklist', $blacklist );
+ $user->setOption( $userOption, $blacklist );
$user->saveSettings();
}
}
/**
- * Mute emails from target
+ * Mute target
+ * @param string $userOption up_property key that holds the blacklist
*/
- private function muteEmailsFromTarget() {
+ private function muteTarget( $userOption ) {
// avoid duplicates just in case
- if ( !$this->isTargetBlacklisted() ) {
- $blacklist = $this->getBlacklist();
+ if ( !$this->isTargetBlacklisted( $userOption ) ) {
+ $blacklist = $this->getBlacklist( $userOption );
$blacklist[] = $this->targetCentralId;
$blacklist = implode( "\n", $blacklist );
$user = $this->getUser();
- $user->setOption( 'email-blacklist', $blacklist );
+ $user->setOption( $userOption, $blacklist );
$user->saveSettings();
}
}
/**
* @inheritDoc
*/
- protected function alterForm( HTMLForm $form ) {
+ protected function getForm() {
+ $form = parent::getForm();
$form->setId( 'mw-specialmute-form' );
$form->setHeaderText( $this->msg( 'specialmute-header', $this->target )->parse() );
$form->setSubmitTextMsg( 'specialmute-submit' );
$form->setSubmitID( 'save' );
+
+ return $form;
}
/**
* @inheritDoc
*/
protected function getFormFields() {
- if ( !$this->enableUserEmailBlacklist || !$this->enableUserEmail ) {
- throw new ErrorPageError( 'specialmute', 'specialmute-error-email-blacklist-disabled' );
+ $fields = [];
+ if (
+ $this->enableUserEmailBlacklist &&
+ $this->enableUserEmail &&
+ $this->getUser()->getEmailAuthenticationTimestamp()
+ ) {
+ $fields['email-blacklist'] = [
+ 'type' => 'check',
+ 'label-message' => 'specialmute-label-mute-email',
+ 'default' => $this->isTargetBlacklisted( 'email-blacklist' ),
+ ];
}
- if ( !$this->getUser()->getEmailAuthenticationTimestamp() ) {
- throw new ErrorPageError( 'specialmute', 'specialmute-error-email-preferences' );
- }
+ Hooks::run( 'SpecialMuteModifyFormFields', [ $this, &$fields ] );
- $fields['MuteEmail'] = [
- 'type' => 'check',
- 'label-message' => 'specialmute-label-mute-email',
- 'default' => $this->isTargetBlacklisted(),
- ];
+ if ( count( $fields ) == 0 ) {
+ throw new ErrorPageError( 'specialmute', 'specialmute-error-no-options' );
+ }
return $fields;
}
}
/**
+ * @param string $userOption
* @return bool
*/
- private function isTargetBlacklisted() {
- $blacklist = $this->getBlacklist();
- return in_array( $this->targetCentralId, $blacklist );
+ public function isTargetBlacklisted( $userOption ) {
+ $blacklist = $this->getBlacklist( $userOption );
+ return in_array( $this->targetCentralId, $blacklist, true );
}
/**
+ * @param string $userOption
* @return array
*/
- private function getBlacklist() {
- $blacklist = $this->getUser()->getOption( 'email-blacklist' );
+ private function getBlacklist( $userOption ) {
+ $blacklist = $this->getUser()->getOption( $userOption );
if ( !$blacklist ) {
return [];
}
"specialmute-success": "Your mute preferences have been updated. See all muted users in [[Special:Preferences|your preferences]].",
"specialmute-submit": "Confirm",
"specialmute-label-mute-email": "Mute emails from this user",
- "specialmute-header": "Please select your mute preferences for {{BIDI:[[User:$1]]}}.",
+ "specialmute-header": "Please select your mute preferences for <b>{{BIDI:[[User:$1]]}}</b>.",
"specialmute-error-invalid-user": "The username requested could not be found.",
- "specialmute-error-email-blacklist-disabled": "Muting users from sending you emails is not enabled.",
- "specialmute-error-email-preferences": "You must confirm your email address before you can mute a user. You may do so from [[Special:Preferences]].",
+ "specialmute-error-no-options": "Mute features are unavailable. This might be because: you haven't confirmed your email address or the wiki administrator has disabled email features and/or email blacklist for this wiki.",
"specialmute-email-footer": "To manage email preferences for {{BIDI:$2}} please visit <$1>.",
"specialmute-login-required": "Please log in to change your mute preferences.",
"mute-preferences": "Mute preferences",
/**
* @covers SpecialMute::execute
- * @expectedExceptionMessage Muting users from sending you emails is not enabled
+ * @expectedExceptionMessage Mute features are unavailable
* @expectedException ErrorPageError
*/
public function testEmailBlacklistNotEnabled() {
+ $this->setTemporaryHook(
+ 'SpecialMuteModifyFormFields',
+ null
+ );
+
$this->setMwGlobals( [
'wgEnableUserEmailBlacklist' => false
] );
$loggedInUser->confirmEmail();
$loggedInUser->saveSettings();
- $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => 1 ], true );
+ $fauxRequest = new FauxRequest( [ 'wpemail-blacklist' => true ], true );
list( $html, ) = $this->executeSpecialPage(
$targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
);
$loggedInUser->confirmEmail();
$loggedInUser->saveSettings();
- $fauxRequest = new FauxRequest( [ 'wpMuteEmail' => false ], true );
+ $fauxRequest = new FauxRequest( [ 'wpemail-blacklist' => false ], true );
list( $html, ) = $this->executeSpecialPage(
$targetUser->getName(), $fauxRequest, 'qqx', $loggedInUser
);